package com.hoshiicloud.withdraw.util.tanhaogong;

import net.sf.json.JSONObject;

import java.util.*;

@SuppressWarnings("ALL")
public class Demo {

	//加密秘钥
	private String key = "";

	/**
	 * 3.1	签约信息上传
	 */
	public void userAdd() {
		//用户信息
		JSONObject param = new JSONObject();

		param.put("name", "张三");
		param.put("idNo", "2343445");
		param.put("signUrl", "https://www.baidu.com");

		LinkedHashMap headers = new LinkedHashMap();

		headers.put("Content-Type", "application/json");
		headers.put("Charset", "UTF-8");
		headers.put("X-Open-App-Id", "714");
		headers.put("X-Open-App-Secret", "5bb09a58a0bfca7f6e0");


		JSONObject jsonResult = ToolsHelper.sendPOST("https://java-api.tanhaogong.com/tanhaogong/foreign/user/add", param.toString(), headers, "UTF-8");

		System.out.println(jsonResult);


	}


	/**
	 * 3.2	自由职业者签署
	 */
	public void handPersonSignTask() {

		try {
			JSONObject paramMap = new JSONObject();

			paramMap.put("name", "张三");
			paramMap.put("idNo", "342422199608139816");
			paramMap.put("phone", "15256414610");
			paramMap.put("inAcctNo", "8239472342342342");
			paramMap.put("inAcctBankName", "平安银行");

			LinkedHashMap headers = new LinkedHashMap();

			headers.put("Content-Type", "application/json");
			headers.put("Charset", "UTF-8");
			headers.put("X-Open-App-Id", "714");
			headers.put("X-Open-App-Secret", "5bb09a58a0bfca7f6e0");

			//获取加密参数
			String s = RSAUtils.encryptByPrivateKey(paramMap.toString().getBytes(), key);


			JSONObject jsonResult = ToolsHelper.sendPOST("https://java-api.tanhaogong.com/tanhaogong/foreign/user/handPersonSignTask", s, headers, "UTF-8");


			System.out.println(jsonResult);

		} catch (Exception e) {
			e.printStackTrace();

		}
	}

	/**
	 * 3.3		自由职业者签署签署状态查询
	 */
	public void findSignStatus() {

		try {
			JSONObject paramMap = new JSONObject();

			paramMap.put("idNo", "342422199608137816");

			LinkedHashMap headers = new LinkedHashMap();

			headers.put("Content-Type", "application/json");
			headers.put("Charset", "UTF-8");
			headers.put("X-Open-App-Id", "714");
			headers.put("X-Open-App-Secret", "5bb09a58a0bfca7f6e0");
			//获取加密参数
			String s = RSAUtils.encryptByPrivateKey(paramMap.toString().getBytes(), key);

			JSONObject jsonResult = ToolsHelper.sendPOST("https://java-api.tanhaogong.com/tanhaogong/foreign/user/get/signedStatus", s, headers, "UTF-8");


			System.out.println(jsonResult);

		} catch (Exception e) {
			e.printStackTrace();

		}
	}

	/**
	 * 3.4		批量付款接口
	 */
	public void payBatch() {

		try {
			List<Map<String, String>> list = new ArrayList<>();


			Map map = new HashMap();

			map.put("orderNo", DateUtils.getTodayStr("yyyyMMddHHss") + RandomNumberGenerator.generateNumber());
			map.put("tranAmount", "0.1");
			map.put("inAcctName", "张三");
			map.put("inAcctNo", "3453453453");
			map.put("inAcctBankName", "招商银行");
			map.put("idNo", "342422199608137816");

			Map map2 = new HashMap();

			map2.put("orderNo", DateUtils.getTodayStr("yyyyMMddHHss") + RandomNumberGenerator.generateNumber());
			map2.put("tranAmount", "0.1");
			map2.put("inAcctName", "李四");
			map2.put("inAcctNo", "3453453453");
			map2.put("inAcctBankName", "招商银行");
			map2.put("idNo", "342422199608137817");

			list.add(map);
			list.add(map2);


			JSONObject paramMap = new JSONObject();

			paramMap.put("totalSum", 2);
			paramMap.put("totalAmount", "0.2");
			paramMap.put("batchNo", DateUtils.getTodayStr("yyyyMMddHHss") + RandomNumberGenerator.generateNumber());
			paramMap.put("notifyUrl", "https://www.baidu.com/notify");
			paramMap.put("useSignInfo", 2);
			paramMap.put("authCode", "38457839vghnjdf34678nc3v375");
			paramMap.put("payeeList", list);


			LinkedHashMap headers = new LinkedHashMap();

			headers.put("Content-Type", "application/json");
			headers.put("Charset", "UTF-8");
			headers.put("X-Open-App-Id", "714");
			headers.put("X-Open-App-Secret", "5bb09a58a0bfca7f6e0");

			//获取加密参数
			String s = RSAUtils.encryptByPrivateKey(paramMap.toString().getBytes(), key);

			JSONObject jsonResult = ToolsHelper.sendPOST("https://java-api.tanhaogong.com/tanhaogong/foreign/pay/batch", s, headers, "UTF-8");


			System.out.println(jsonResult);

		} catch (Exception e) {
			e.printStackTrace();

		}
	}
}
